\subsection{Event Based Programming}

	Event based programming or event driven programming is a type of programming where the program reacts to certain activity. Activities in this case are mouse actions, keyboard actions or just some interaction. These activities are more commonly refered to as \texttt{Events}.
	The figure \ref{fig:designpatternevent} shows the design pattern for the event handler.
	
	\begin{figure}
		\begin{center}
			\includegraphics[width=0.7\textwidth]{./Analysis/tictactoe.jpg}
		\end{center}
		\caption{Shows the $3 \times 3$ board of Tic Tac Toe}
		\label{fig:designpatternevent}
	\end{figure}
	
	This figure shows a stream of events which are handled by the dispatcher. The dispatcher analysises each event to determine which handler can be used for that particular event. If a dispatcher can't find a fitting handler there are two options which can be implemented. The handler can either discard the event or it can throw an exception to prevent further invalid events. When implementing this design there has to be implemented a special handler to handle an end of event stream which would indicate that the program should be terminated. 
	Event based programming is most commonly used in \texttt{Graphical User Interfaces} (GUI). The way it is implemented is most common a loop which waits for an event to occure and then processes the event as it occures. Here an event stream queue is used for queueing the events as they come in.

	do forever()
	{
		//setting the event to analyse the type
		event = get.eventfromstream();
		
		//Checking the types as follows.
		if(event.typeof()==EndOfEventStream);
			break;
			
		if(event.typeof() == ...)
			//function to be executes goes here
		else
			//handle event types which are not implemented
	}
	
	